package pattern.behavioral.Interpreter.simple;

/**
 * @author: chaoyang.ren  
 * @date:Jun 22, 2017  
 * @time:4:30:18 PM   
 * @email:chaoyang.ren@foxmail.com  
 * @version: 1.0
 */
public class Not extends Expression{
    
    private Expression expression;
    
    public Not(Expression exp){
        this.expression = exp;
    }

    @Override
    public boolean equals(Object obj) {
        
        if(obj != null && obj instanceof Not){
            return expression.equals(((Not)obj).expression);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }

    @Override
    public boolean interpret(Context ctx) {
        return !expression.interpret(ctx);
    }

    @Override
    public String toString() {
        return "( Not " + expression.toString() + ")";
    }
    
}

